<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />



  <meta name="google-site-verification" content="true" />














  
  
    
  
  <link href="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.lug.ustc.edu.cn/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






  

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Java," />








  <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico?v=5.1.2" />






<meta name="keywords" content="Java">
<meta property="og:type" content="article">
<meta property="og:title" content="Java根据圆心经纬度、半径获取圆的点集">
<meta property="og:url" content="http://hunfan.top/2018/09/29/Java根据圆心经纬度、半径获取圆的点集/index.html">
<meta property="og:site_name" content="混饭&#39;s Notes">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://hunfan.top/upload/homePage/20180930150201.jpg">
<meta property="og:image" content="http://hunfan.top/upload/获取圆经纬度点集/获取圆经纬度点集_1.jpg">
<meta property="og:image" content="http://hunfan.top/upload/获取圆经纬度点集/获取圆经纬度点集_墨卡托投影_2.gif">
<meta property="og:updated_time" content="2019-01-10T02:53:53.368Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java根据圆心经纬度、半径获取圆的点集">
<meta name="twitter:image" content="http://hunfan.top/upload/homePage/20180930150201.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '77ZW8HG1F0',
      apiKey: '924aaf9b16831d3af864330abb1b94cf',
      indexName: 'github',
      hits: {"per_page":10},
      labels: {"input_placeholder":"输入关键词进行搜索","hits_empty":"找不到关于” ${query} ”的文章","hits_stats":"共找到 ${hits} 篇文章，花了 ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://hunfan.top/2018/09/29/Java根据圆心经纬度、半径获取圆的点集/"/>



<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>



	<meta name="google-site-verification" content="7cmTqceXKE0HPzXSCTPWvChlMw-OZuC3GLENr9qj9XM" />


  <title>Java根据圆心经纬度、半径获取圆的点集 | 混饭's Notes</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
	<a target="_blank" href="https://github.com/hf-hf" class="github-corner" aria-label="Fork me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
	
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">混饭's Notes</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Quick notes</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/09/29/Java根据圆心经纬度、半径获取圆的点集/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Java根据圆心经纬度、半径获取圆的点集</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-09-29T16:41:54+08:00">
                2018-09-29
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2018/09/29/Java根据圆心经纬度、半径获取圆的点集/" class="leancloud_visitors" data-flag-title="Java根据圆心经纬度、半径获取圆的点集">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="/upload/homePage/20180930150201.jpg" alt="homePage"><br><a id="more"></a></p>
<h2 id="情景"><a href="#情景" class="headerlink" title="情景"></a>情景</h2><p>最近有对接第三方的需求，需要在后台通过圆心点经纬度、半径获取圆的经纬度点集。</p>
<h2 id="根据圆心、半径计算圆上点集的算法"><a href="#根据圆心、半径计算圆上点集的算法" class="headerlink" title="根据圆心、半径计算圆上点集的算法"></a>根据圆心、半径计算圆上点集的算法</h2><p>首先来分析一下，这个问题可以转换成数学上的平面坐标系计算，已知圆心坐标(x0,y0)，半径r，角度a0，求圆上任一点公式为：</p>
<blockquote>
<p>x1 = x0 + r <em> cos(a0 </em> π/180)<br>y1 = y0 + r <em> sin(a0 </em> π/180)</p>
</blockquote>
<p>其中a0 * π/180(角度乘以π/180)，目的是将角度a0转换为弧度。</p>
<p>下面将平面上的圆等分为6份(如下图)，根据公式代入圆心坐标、弧度和半径计算出对应圆弧半径与圆交点的平面坐标。</p>
<p><img src="/upload/获取圆经纬度点集/获取圆经纬度点集_1.jpg" alt="获取圆经纬度点集_1"></p>
<p>这样就获得了6个平面圆上的坐标点，(x1,y1)、(x2,y2)…(x6,y6)，注意此时的点只是数学意义上的点，接下来需要将平面的点投影到地图上，获取地图经纬度的点集。</p>
<h2 id="将平面坐标投影到地图"><a href="#将平面坐标投影到地图" class="headerlink" title="将平面坐标投影到地图"></a>将平面坐标投影到地图</h2><p>在介绍如何将平面坐标投影到地图之前，我们首先需要了解一个概念:墨卡托投影。</p>
<p>众所周知，地球是一个不规则的球体，而我们平时看到的地图大多是平面的，那么如何将一个三维的地球画到平面上的呢。</p>
<p>墨卡托投影就是将三维的地球表示在一个二维平面上的方法之一，也是应用得最广泛的方法，我们平时看到的谷歌地图，百度地图，都是使用的墨卡托投影。</p>
<p>墨卡托投影展开方式见下图:</p>
<p><img src="/upload/获取圆经纬度点集/获取圆经纬度点集_墨卡托投影_2.gif" alt="获取圆经纬度点集_墨卡托投影"></p>
<blockquote>
<p>什么是墨卡托投影？<br>墨卡托投影（Mercator Projection），又名“等角正轴圆柱投影”，荷兰地图学家墨卡托（Mercator）在1569年拟定，假设地球被围在一个中空的圆柱里，其赤道与圆柱相接触，然后再假想地球中心有一盏灯，把球面上的图形投影到圆柱体上，再把圆柱体展开，这就是一幅标准纬线为零度（即赤道）的“墨卡托投影”绘制出的世界地图。</p>
</blockquote>
<p>那么我们如何将已经计算出的平面圆坐标点转换成地图的经纬度点呢？具体实现原理这里就不列举了，有兴趣了解的同学可以查看<a href="https://blog.csdn.net/ywjatjd/article/details/62896201#%E4%B8%89%E5%9D%90%E6%A0%87%E7%B3%BB%E6%8A%95%E5%BD%B1%E7%9A%84%E5%AE%9E%E7%8E%B0source-code" target="_blank" rel="noopener">经纬度坐标映射到平面直角坐标系</a>，该地址上有详细的解释，其中有以C#实现的将XY坐标转经纬度的代码，本文将该部分以Java实现应用到点集计算中，在此感谢大神们的分享。</p>
<h2 id="解决方案-代码"><a href="#解决方案-代码" class="headerlink" title="解决方案(代码)"></a>解决方案(代码)</h2><p>这里通过上述的平面数学公式、XY坐标转经纬度，结合后实现的根据圆心经纬度、半径获取圆点集的最终实现代码如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br></pre></td><td class="code"><pre><span class="line">import java.math.BigDecimal;</span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import com.alibaba.fastjson.JSON;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * Gis工具类</span><br><span class="line"> * @author hefan</span><br><span class="line"> * @date 2018/9/27 8:55</span><br><span class="line"> */</span><br><span class="line">public class GisUtils &#123;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 反向转换程序中的迭代次数</span><br><span class="line">     */</span><br><span class="line">    private final int iterativeTimes = 10;</span><br><span class="line">    /**</span><br><span class="line">     * 反向转换程序中的迭代初始值</span><br><span class="line">     */</span><br><span class="line">    private final double iterativeValue = 0;</span><br><span class="line">    /**</span><br><span class="line">     * 椭球体长轴,千米</span><br><span class="line">     */</span><br><span class="line">    private double _A = 6378.137;</span><br><span class="line">    /**</span><br><span class="line">     * 椭球体短轴,千米</span><br><span class="line">     */</span><br><span class="line">    private double _B = 6356.752314;</span><br><span class="line">    /**</span><br><span class="line">     * 标准纬度,弧度</span><br><span class="line">     */</span><br><span class="line">    private double _B0 = 0;</span><br><span class="line">    /**</span><br><span class="line">     * 原点经度,弧度</span><br><span class="line">     */</span><br><span class="line">    private double _L0 = 0;</span><br><span class="line">    /**</span><br><span class="line">     * 默认点集点数量</span><br><span class="line">     */</span><br><span class="line">    private static final int _defaultNumPoints = 40;</span><br><span class="line">    /**</span><br><span class="line">     * 地球半径</span><br><span class="line">     */</span><br><span class="line">    //public static final double _R = 6371000.79;</span><br><span class="line"></span><br><span class="line">    private GisUtils() &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 获取实例</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 10:05</span><br><span class="line">     */</span><br><span class="line">    public static GisUtils getInstance()&#123;</span><br><span class="line">        return new GisUtils();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 角度到弧度的转换</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:07</span><br><span class="line">     */</span><br><span class="line">    public double degreeToRad(double degree) &#123;</span><br><span class="line">        return Math.PI * degree / 180;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 弧度到角度的转换</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:07</span><br><span class="line">     */</span><br><span class="line">    public double radToDegree(double rad) &#123;</span><br><span class="line">        return (180 * rad) / Math.PI;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 设定_A与_B</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:07</span><br><span class="line">     */</span><br><span class="line">    public void setAB(double a, double b) &#123;</span><br><span class="line">        if (a &lt;= 0 || b &lt;= 0) &#123;</span><br><span class="line">            return;</span><br><span class="line">        &#125;</span><br><span class="line">        _A = a;</span><br><span class="line">        _B = b;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 设定_B0</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:27</span><br><span class="line">     */</span><br><span class="line">    public void setLB0(double pmtL0, double pmtB0) &#123;</span><br><span class="line">        double l0 = degreeToRad(pmtL0);</span><br><span class="line">        if (l0 &lt; -Math.PI || l0 &gt; Math.PI) &#123;</span><br><span class="line">            return;</span><br><span class="line">        &#125;</span><br><span class="line">        _L0 = l0;</span><br><span class="line"></span><br><span class="line">        double b0 = degreeToRad(pmtB0);</span><br><span class="line">        if (b0 &lt; -Math.PI / 2 || b0 &gt; Math.PI / 2) &#123;</span><br><span class="line">            return;</span><br><span class="line">        &#125;</span><br><span class="line">        _B0 = b0;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 经纬度转XY坐标</span><br><span class="line">     * pmtLB0: 参考点经纬度</span><br><span class="line">     * pmtLB1: 要转换的经纬度</span><br><span class="line">     * 返回值: 直角坐标，单位：公里</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:04</span><br><span class="line">     */</span><br><span class="line">    public Point lBToXY(Point pmtLB0, Point pmtLB1) &#123;</span><br><span class="line">        setLB0(pmtLB0.getLng(), pmtLB0.getLat());</span><br><span class="line"></span><br><span class="line">        double B = degreeToRad(pmtLB1.getLat());</span><br><span class="line">        double L = degreeToRad(pmtLB1.getLng());</span><br><span class="line"></span><br><span class="line">        Point xy = new Point(0,0);</span><br><span class="line">        //xy.setLat(0);</span><br><span class="line">        //xy.setLng(0);</span><br><span class="line"></span><br><span class="line">        double f/*扁率*/, e/*第一偏心率*/, e_/*第二偏心率*/, NB0/*卯酉圈曲率半径*/, K, dtemp;</span><br><span class="line">        double E = Math.exp(1);</span><br><span class="line">        if (L &lt; -Math.PI || L &gt; Math.PI || B &lt; -Math.PI / 2 || B &gt; Math.PI / 2) &#123;</span><br><span class="line">            return xy;</span><br><span class="line">        &#125;</span><br><span class="line">        if (_A &lt;= 0 || _B &lt;= 0) &#123;</span><br><span class="line">            return xy;</span><br><span class="line">        &#125;</span><br><span class="line">        f = (_A - _B) / _A;</span><br><span class="line">        dtemp = 1 - (_B / _A) * (_B / _A);</span><br><span class="line">        if (dtemp &lt; 0) &#123;</span><br><span class="line">            return xy;</span><br><span class="line">        &#125;</span><br><span class="line">        e = Math.sqrt(dtemp);</span><br><span class="line">        dtemp = (_A / _B) * (_A / _B) - 1;</span><br><span class="line">        if (dtemp &lt; 0) &#123;</span><br><span class="line">            return xy;</span><br><span class="line">        &#125;</span><br><span class="line">        e_ = Math.sqrt(dtemp);</span><br><span class="line"></span><br><span class="line">        NB0 = ((_A * _A) / _B) / Math.sqrt(1 + e_ * e_ * Math.cos(_B0) * Math.cos(_B0));</span><br><span class="line">        K = NB0 * Math.cos(_B0);</span><br><span class="line">        xy.setLng(K * (L - _L0));</span><br><span class="line">        xy.setLat(K * Math.log(Math.tan(Math.PI / 4 + (B) / 2) * Math.pow((1 - e * Math.sin(B)) / (1 + e * Math.sin(B)), e / 2)));</span><br><span class="line">        double y0 = K * Math.log(Math.tan(Math.PI / 4 + (_B0) / 2) * Math.pow((1 - e * Math.sin(_B0)) / (1 + e * Math.sin(_B0)), e / 2));</span><br><span class="line">        xy.setLat(xy.getLat() - y0);</span><br><span class="line"></span><br><span class="line">        //正常的Y坐标系（向上）转程序的Y坐标系（向下）</span><br><span class="line">        xy.setLat(-xy.getLat());</span><br><span class="line"></span><br><span class="line">        return xy;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * XY坐标转经纬度</span><br><span class="line">     * pmtLB0: 参考点经纬度</span><br><span class="line">     * pmtXY: 要转换的XY坐标，单位：公里</span><br><span class="line">     * 返回值: 经纬度</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:04</span><br><span class="line">     */</span><br><span class="line">    public Point xYtoLB(Point pmtLB0, Point pmtXY) &#123;</span><br><span class="line">        setLB0(pmtLB0.getLng(), pmtLB0.getLat());</span><br><span class="line"></span><br><span class="line">        double X = pmtXY.getLng();</span><br><span class="line">        double Y = -pmtXY.getLat();//程序的Y坐标系（向下）转正常的Y坐标系（向上）</span><br><span class="line"></span><br><span class="line">        double B = 0, L = 0;</span><br><span class="line"></span><br><span class="line">        Point lb = new Point(0,0);</span><br><span class="line">        //lb.setLat(0);</span><br><span class="line">        //lb.setLng(0);</span><br><span class="line"></span><br><span class="line">        double f/*扁率*/, e/*第一偏心率*/, e_/*第二偏心率*/, NB0/*卯酉圈曲率半径*/, K, dtemp;</span><br><span class="line">        double E = Math.exp(1);</span><br><span class="line"></span><br><span class="line">        if (_A &lt;= 0 || _B &lt;= 0) &#123;</span><br><span class="line">            return lb;</span><br><span class="line">        &#125;</span><br><span class="line">        f = (_A - _B) / _A;</span><br><span class="line">        dtemp = 1 - (_B / _A) * (_B / _A);</span><br><span class="line">        if (dtemp &lt; 0) &#123;</span><br><span class="line">            return lb;</span><br><span class="line">        &#125;</span><br><span class="line">        e = Math.sqrt(dtemp);</span><br><span class="line">        dtemp = (_A / _B) * (_A / _B) - 1;</span><br><span class="line">        if (dtemp &lt; 0) &#123;</span><br><span class="line">            return lb;</span><br><span class="line">        &#125;</span><br><span class="line">        e_ = Math.sqrt(dtemp);</span><br><span class="line">        NB0 = ((_A * _A) / _B) / Math.sqrt(1 + e_ * e_ * Math.cos(_B0) * Math.cos(_B0));</span><br><span class="line">        K = NB0 * Math.cos(_B0);</span><br><span class="line"></span><br><span class="line">        double y0 = K * Math.log(Math.tan(Math.PI / 4 + (_B0) / 2) * Math.pow((1 - e * Math.sin(_B0)) / (1 + e * Math.sin(_B0)), e / 2));</span><br><span class="line">        Y = Y + y0;</span><br><span class="line"></span><br><span class="line">        L = X / K + _L0;</span><br><span class="line">        B = iterativeValue;</span><br><span class="line"></span><br><span class="line">        for (int i = 0; i &lt; iterativeTimes; i++) &#123;</span><br><span class="line">            B = Math.PI / 2 - 2 * Math.atan(Math.pow(E, (-Y / K)) * Math.pow(E, (e / 2) * Math.log((1 - e * Math.sin(B)) / (1 + e * Math.sin(B)))));</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        lb.setLng(radToDegree(L));</span><br><span class="line">        lb.setLat(radToDegree(B));</span><br><span class="line"></span><br><span class="line">        return lb;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 获取圆形区域点集（返回区域点集数量默认40个）</span><br><span class="line">     *</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:22</span><br><span class="line">     * @param centerPointLat    中心点纬度</span><br><span class="line">     * @param centerPointLng    中心点经度</span><br><span class="line">     * @param radius            圆形区域半径（单位：千米）</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    public List&lt;double[]&gt; getCircularAreaPoints(double centerPointLng,double centerPointLat,</span><br><span class="line">                                                       double radius)&#123;</span><br><span class="line">        return getCircularAreaPoints(new Point(centerPointLng, centerPointLat),</span><br><span class="line">                radius, _defaultNumPoints);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 获取圆形区域点集</span><br><span class="line">     *</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:22</span><br><span class="line">     * @param centerPointLng    中心点经度</span><br><span class="line">     * @param centerPointLat    中心点纬度</span><br><span class="line">     * @param radius            圆形区域半径（单位：千米）</span><br><span class="line">     * @param numPoints         返回圆区域点数量</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    public List&lt;double[]&gt; getCircularAreaPoints(double centerPointLng,double centerPointLat,</span><br><span class="line">                                                       double radius, int numPoints)&#123;</span><br><span class="line">        return getCircularAreaPoints(new Point(centerPointLng,centerPointLat),</span><br><span class="line">                radius, numPoints);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 获取圆形区域点集</span><br><span class="line">     *</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:13</span><br><span class="line">     * @param centerPoint   圆心点（平面坐标转经纬度参考点）</span><br><span class="line">     * @param radius        圆形区域半径（单位：千米）</span><br><span class="line">     * @param numPoints     返回圆区域点数量</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    public List&lt;double[]&gt; getCircularAreaPoints(Point centerPoint, double radius, int numPoints) &#123;</span><br><span class="line">        List&lt;double[]&gt; points = new ArrayList&lt;&gt;();</span><br><span class="line">        double phase = 2 * Math.PI / numPoints;</span><br><span class="line">        Point tmpPoint = null;</span><br><span class="line">        for (int i = 0; i &lt; numPoints; i++) &#123;</span><br><span class="line">            /**</span><br><span class="line">             * 计算坐标点</span><br><span class="line">             */</span><br><span class="line">            double dx = (radius * Math.cos(i * phase));</span><br><span class="line">            double dy = (radius * Math.sin(i * phase));</span><br><span class="line"></span><br><span class="line">            /**</span><br><span class="line">             * 转换成经纬度</span><br><span class="line">             */</span><br><span class="line">            tmpPoint = xYtoLB(new Point(centerPoint.getLat(),centerPoint.getLng()),</span><br><span class="line">                    new Point(dx, dy));</span><br><span class="line">            points.add(new double[]&#123;roundDown6(tmpPoint.getLng()),</span><br><span class="line">                    roundDown6(tmpPoint.getLat())&#125;);</span><br><span class="line">        &#125;</span><br><span class="line">        return points;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 获取圆形区域点集（地图点集）</span><br><span class="line">     *</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:13</span><br><span class="line">     * @param centerPoint   圆心点（平面坐标转经纬度参考点）</span><br><span class="line">     * @param radius        圆形区域半径（单位：千米）</span><br><span class="line">     * @param numPoints     返回圆区域点数量</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    public List&lt;Point&gt; getCircularAreaMapPoints(Point centerPoint, double radius, int numPoints) &#123;</span><br><span class="line">        List&lt;Point&gt; points = new ArrayList&lt;&gt;();</span><br><span class="line">        double phase = 2 * Math.PI / numPoints;</span><br><span class="line">        Point tmpPoint = null;</span><br><span class="line">        for (int i = 0; i &lt; numPoints; i++) &#123;</span><br><span class="line">            /**</span><br><span class="line">             * 计算坐标点</span><br><span class="line">             */</span><br><span class="line">            double dx = (radius * Math.cos(i * phase));</span><br><span class="line">            double dy = (radius * Math.sin(i * phase));</span><br><span class="line"></span><br><span class="line">            /**</span><br><span class="line">             * 转换成经纬度</span><br><span class="line">             */</span><br><span class="line">            tmpPoint = xYtoLB(new Point(centerPoint.getLng(),centerPoint.getLat()),</span><br><span class="line">                    new Point(dx, dy));</span><br><span class="line">            points.add(new Point(roundDown6(tmpPoint.getLng()),</span><br><span class="line">                    roundDown6(tmpPoint.getLat())));</span><br><span class="line">        &#125;</span><br><span class="line">        return points;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 获取圆形区域点集（返回区域点集数量默认40个）（地图点集）</span><br><span class="line">     *</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:22</span><br><span class="line">     * @param centerPointLat    中心点纬度</span><br><span class="line">     * @param centerPointLng    中心点经度</span><br><span class="line">     * @param radius            圆形区域半径（单位：千米）</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    public String getCircularAreaMapPoints(double centerPointLng,double centerPointLat,</span><br><span class="line">                                                double radius)&#123;</span><br><span class="line">        List&lt;Point&gt; points = getCircularAreaMapPoints(new Point(centerPointLng, centerPointLat),</span><br><span class="line">                radius, _defaultNumPoints);</span><br><span class="line">        return JSON.toJSONString(points);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 保留小数点后6位，不进位</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 10:14</span><br><span class="line">     */</span><br><span class="line">    public double roundDown6(double value) &#123;</span><br><span class="line">        return Double.valueOf(new BigDecimal(value).setScale(6,</span><br><span class="line">                BigDecimal.ROUND_DOWN).doubleValue());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 点</span><br><span class="line">     * @author hefan</span><br><span class="line">     * @date 2018/9/27 9:26</span><br><span class="line">     */</span><br><span class="line">     class Point &#123;</span><br><span class="line">        /**</span><br><span class="line">         * 经度</span><br><span class="line">         */</span><br><span class="line">        private double lng;</span><br><span class="line">        /**</span><br><span class="line">         * 纬度</span><br><span class="line">         */</span><br><span class="line">        private double lat;</span><br><span class="line"></span><br><span class="line">        public double getLng() &#123;</span><br><span class="line">            return lng;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        public void setLng(double lng) &#123;</span><br><span class="line">            this.lng = lng;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        public double getLat() &#123;</span><br><span class="line">            return lat;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        public void setLat(double lat) &#123;</span><br><span class="line">            this.lat = lat;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        public Point(double lng, double lat) &#123;</span><br><span class="line">            this.lng = lng;</span><br><span class="line">            this.lat = lat;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        long startTime = System.currentTimeMillis();//获取开始时间</span><br><span class="line">        String tmp = GisUtils.getInstance().getCircularAreaMapPoints(36.120869,</span><br><span class="line">                120.420729, 1);</span><br><span class="line">        System.out.println(tmp);</span><br><span class="line">        long endTime = System.currentTimeMillis();    //获取结束时间</span><br><span class="line">        System.out.println(&quot;程序运行时间：&quot; + (endTime - startTime) + &quot;ms&quot;);    //输出程序运行时间</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>测试程序执行效率，在生成圆形区域点集点数量默认40的情况下，运行时间小于10ms。</p>
<h2 id="总结与反思"><a href="#总结与反思" class="headerlink" title="总结与反思"></a>总结与反思</h2><p>除了CUID，你还会些什么？’(°ー°〃)<br>知其然，更要知其所以然。~(￣0￣)/</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java/" rel="tag"># Java</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/09/25/Spring-Cloud-Feign调用远端ModelAttribute接口问题解决/" rel="next" title="Spring Cloud Feign调用远端ModelAttribute接口问题解决">
                <i class="fa fa-chevron-left"></i> Spring Cloud Feign调用远端ModelAttribute接口问题解决
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/10/12/从Netty3升级到Netty4实战/" rel="prev" title="从Netty3升级到Netty4实战">
                从Netty3升级到Netty4实战 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        <!-- Go to www.addthis.com/dashboard to customize your tools -->
<div class="addthis_inline_share_toolbox">
  <script type = "text/javascript" src = "//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5b4c0089687a63d1" async = "async" ></script>
</div>

      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zMzEyNC85Njgz"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="混饭" />
          <p class="site-author-name" itemprop="name">混饭</p>
           
              <p class="site-description motion-element" itemprop="description">重度拖延症患者(-__-)b</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives/">
            
                <span class="site-state-item-count">52</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">45</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hf-hf" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                    
                      GitHub
                    
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://gitee.com/hf-hf" target="_blank" title="Gitee">
                  
                    <i class="fa fa-fw fa-gitee"></i>
                  
                    
                      Gitee
                    
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#情景"><span class="nav-number">1.</span> <span class="nav-text">情景</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#根据圆心、半径计算圆上点集的算法"><span class="nav-number">2.</span> <span class="nav-text">根据圆心、半径计算圆上点集的算法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#将平面坐标投影到地图"><span class="nav-number">3.</span> <span class="nav-text">将平面坐标投影到地图</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#解决方案-代码"><span class="nav-number">4.</span> <span class="nav-text">解决方案(代码)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结与反思"><span class="nav-number">5.</span> <span class="nav-text">总结与反思</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">混饭</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" href="https://coding.net/pages">Hosted by CODING Pages</a> 强力驱动</div>



        
<div class="busuanzi-count">
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="//cdn.jsdelivr.net/jquery/2.1.3/jquery.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/fastclick/1.0.6/fastclick.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazyload/1.9.3/jquery.lazyload.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.ui.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.pack.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>





  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  








  




  
  
  
    
  
  <link rel="stylesheet" href="//cdn.bootcss.com/instantsearch.js/1.5.0/instantsearch.min.css">

  
  
    
  
  <script src="//cdn.bootcss.com/instantsearch.js/1.5.0/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.2"></script>



  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("FbdjjSByqhjHC2t0f5DiTzXi-gzGzoHsz", "EhyT8E3CKzF9CQcem5hx7ftx");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  

  

</body>
</html>
